<#include "/common/dialogbox.html">
<@header>
</@header>
<@body>
<div class="x_content">
	<form action="${ctx}/system/role/doAuth" method="post" id="roleAuthForm">
		<input type="hidden" value="${(sysRole.id)!}" name="roleId" />
		<table class="table table-hover">
			<#list treeMenuAllowAccesses as vo>
			<tr>
				<td width="128px">
					<label class="radio-box" style="font-weight:bold;">
						<input class="flat checkbox-list" name="mid" type="checkbox" ${(vo.allowAccess)?string('checked','')}  value="${(vo.sysMenu.id)!}">
						<i class="fa fa-folder"></i> ${(vo.sysMenu.menuName)!}
					</label>
				</td>
				<td>
				<#list vo.children as ch>
					<div style="margin-bottom:10px;" class="memu-select">
					<label class="radio-box" style="font-weight:bolder;">
						<input class="flat checkbox-menu" name="mid" type="checkbox" ${(ch.allowAccess)?string('checked','')} value="${(ch.sysMenu.id)!}">
						<i class="fa fa-folder-open"></i> ${(ch.sysMenu.menuName)!} >
					</label>
					<#list ch.children as it>
						<label class="radio-box" style="font-weight:lighter;">
							<input class="flat checkbox-button" name="mid" type="checkbox" ${(it.allowAccess)?string('checked','')} value="${(it.sysMenu.id)!}">
							<i class="fa fa-file"></i> ${(it.sysMenu.menuName)!}
						</label>
					</#list>
					</div>
				</#list>
				</td>
			</tr>
			</#list>
		</table>
	</form>
</div>
</@body>
<@footer>
<script type="text/javascript">
	// 目录层级选中
	$(".checkbox-list").on('ifClicked', function() {
		$(this).parents('tr').find('.checkbox-menu').iCheck('check');
		$(this).parents('tr').find('.checkbox-button').iCheck('check');
	}).on('ifUnchecked', function() {
		$(this).parents('tr').find('.checkbox-menu').iCheck('uncheck');
		$(this).parents('tr').find('.checkbox-button').iCheck('uncheck');
	});
	// 菜单层级选中
	$(".checkbox-menu").on('ifClicked', function() {
		$(this).parents('div.memu-select').find('.checkbox-button').iCheck('check');
	}).on('ifUnchecked', function() {
		$(this).parents('div.memu-select').find('.checkbox-button').iCheck('uncheck');
	});
	// 提交授权
	function submitHandler() {
		//获取checkbox选中的值
		var values = {};
		var $ch = $("input:checkbox:checked");
		var name = {};
		var chvs = [];
		if ($ch && $ch[0]) {
			name = $ch[0].name;
			$ch.each(function() {
				chvs.push($(this).val());
			});
			values[name] = chvs;
		}
		values["roleId"] = $("input[name='roleId']").val();
		$.ajax({
			url : $("#roleAuthForm").attr('action'),
			type : 'POST',
			dataType : "json",
			data : values,
			success : function(data) {
				if (data.code == 200) {
					if (data.msg) {
						parent.layer.msg(data.msg, { icon : 1 });
					} else {
						parent.layer.msg('提交成功', { icon : 1 });
					}
					window.parent.refreshTable();
					parent.layer.closeAll('iframe');
				} else {
					layer.msg(data.msg, { icon : 2 });
				}
			}
		})
	}
</script>
</@footer>
